package net.huashitong.taskGroup.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.taskGroup.dao.DeptListDao;
import net.huashitong.taskGroup.entity.DeptList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DeptListService extends StringPKService<DeptList> {
    @Override
    protected BaseDao<DeptList, String> getDao() {
        return dao;
    }

    @Autowired
    private SysTableService tableService;

    @Autowired
    private DeptListDao dao;

    @Override
    protected void beforeSave(DeptList obj) {
        obj.setSysId(tableService.updateMaxSysId("t_deptlist", null));
    }

    public DeptList getDeptByCode(String code)
    {
        DeptList dept = new DeptList();

        String names ="";
        if(StringUtils.isNotBlank(code))
        {
            String[] arrCode =code.split(",");
            for(String item: arrCode)
            {
                DeptList dp= dao.getDeptByCode(item.trim());

                names=dp.getDeptName()+","+names;
            }
        }
        dept.setDeptCode(code);
        dept.setDeptName(names);
        return dept;
    }
}
